<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
	private $_acl = null;
	
	public function _initDb(){
		$dbOption = $this->getOption("resources");
		$dbOption = $dbOption["db"];
		
		//setup database
		$db = Zend_Db::factory($dbOption["adapter"],$dbOption["params"]);
		
		$db->setFetchMode(Zend_Db::FETCH_ASSOC);
		$db->query("SET NAMES 'utf8'");
		$db->query("SET CHARACTER SET 'utf8'");
		
		Zend_Registry::set("connectDb", $db);
		Zend_Db_Table::setDefaultAdapter($db);
		return $db;
	}
	
	public function _initViewHelpers() {
	
		$this->bootstrap('layout');
		$layout = $this->getResource('layout');
		$view = $layout->getView();
	
		$view->headTitle()->setSeparator(' - ')
		->headTitle('Home Việt');
	}
	
	public function _initRoutes(){
		$front  = $this->getResource('frontcontroller');
		$router = $front->getRouter();
		$config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/routes.xml');
		$router->addConfig($config->routes);
	}
	
	public function _initAutoload(){
		/* $modelLoader = new Zend_Application_Module_Autoloader(array(
				'namespace' => '',
				'basePath' => APPLICATION_PATH.'/modules/admin'));
		if(Zend_Auth::getInstance()->hasIdentity()) {
			Zend_Registry::set('role', Zend_Auth::getInstance()->getStorage()->read()->ROLE_ID);
		} else {
			Zend_Registry::set('role', 'guests');
		}
		
		$this->_acl = new Model_AdminAcl;
		$this->_auth = Zend_Auth::getInstance();
		
		$fc = Zend_Controller_Front::getInstance();
		$fc->registerPlugin(new Plugin_AccessCheck($this->_acl));
		return $modelLoader; */
	}

}

